from datetime import datetime

from datetime import datetime
from sqlalchemy import Column, Integer, String, DateTime, Numeric, PrimaryKeyConstraint, Index

from config.database import Base


class KylinStrategyTradebook(Base):
    """
    策略交易登记簿表
    """

    __tablename__ = 'kylin_strategy_tradebook'
    __table_args__ = (
        Index('idx_strategy_tradebook', 'name', 'price'),
        {'comment': '策略交易登记簿'}
    )
    
    id = Column(Integer, primary_key=True, autoincrement=True, comment='登记簿id')
    name = Column(String(255), nullable=False, comment='策略实例名称')
    price = Column(Numeric(10, 4), nullable=False, comment='价格')
    buy = Column(Integer, nullable=False, default=0, comment='委托买入')
    sell = Column(Integer, nullable=False, default=0, comment='委托卖出')
    bought = Column(Integer, nullable=False, default=0, comment='已经买入')
    sold = Column(Integer, nullable=False, default=0, comment='已经卖出')
    create_time = Column(DateTime, default=datetime.now, comment='创建时间')
    update_time = Column(DateTime, default=datetime.now, onupdate=datetime.now, comment='更新时间')